//
// Created by Scave on 2025/8/28.
//
#include "ExternalListener.h"

NS_RIDER_BEGIN

    SMART_PTR<SceneEventListener> SceneEventListener::WithUpdated(FUNCTION<void(Scene*)> on_updated) {
        return MAKE_SMART_PTR<SceneEventListener>(on_updated);
    }

    SceneEventListener::SceneEventListener() {}

    SceneEventListener::SceneEventListener(FUNCTION<void(Scene*)> on_updated,
                                           FUNCTION<void(Scene*)> on_load, FUNCTION<void(Scene*)> on_unload) {
        this->on_updated = on_updated;
        this->on_load = on_load;
        this->on_unload = on_unload;
    }

    void SceneEventListener::OnUpdated(Scene* scene) {
        if (on_updated) {
            on_updated(scene);
        }
    }

    void SceneEventListener::OnLoad(Scene* scene) {
        if (on_load) {
            on_load(scene);
        }
    }

    void SceneEventListener::OnUnLoad(Scene* scene) {
        if (on_unload) {
            on_unload(scene);
        }
    }

    void SceneEventListener::receive(const SceneLoadEvent& event) {
        OnLoad(event.scene);
    }

    void SceneEventListener::receive(const SceneUnLoadEvent& event) {
        OnUnLoad(event.scene);
    }

    void SceneEventListener::receive(const SceneUpdatedEvent& event) {
        OnUpdated(event.scene);
    }
NS_RIDER_END